/**
 * created by 江心才子, 2019/8/10
 * Copyright (c) 2019, 270628297@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.wyl.mine.userinfo

import android.content.Intent
import android.text.InputType
import android.view.View
import com.wuhenzhizao.titlebar.widget.CommonTitleBar
import com.wyl.libbase.base.BindingActivity
import com.wyl.libbase.extend.autoWired
import com.wyl.libbase.extend.toast
import com.wyl.mine.R
import com.wyl.mine.databinding.EditActivityBinding

/**
 * 项目名称：ShortVideo
 * 创建人：江心才子
 * 创建时间：2019-08-10 16:15
 * 内容描述：
 * 修改说明：
 */

class EditActivity : BindingActivity<EditActivityBinding>() {

    override fun getLayoutId(): Int = R.layout.edit_activity

    override fun initView() {

        binding.titlebar.setListener { _, action, _ ->
            when (action) {
                CommonTitleBar.ACTION_LEFT_BUTTON -> onBackPressed()
                else -> {
                }
            }
        }
    }

    override fun loadData() {
        val title = autoWired("title", "修改资料")
        if (title == "修改昵称") {
            val nickname = autoWired("mUserData", "")
            binding.titlebar.centerTextView.text = title
            binding.edittext.inputType = InputType.TYPE_CLASS_TEXT
            binding.edittext.hint = "请输入昵称"
            binding.edittext.setText(nickname)
            binding.edittext.setSelection(nickname.length)
        }
    }

    override fun onClick(v: View) {
        val text = binding.edittext.text.toString()
        if (text.isEmpty()) {
            toast("昵称不能为空")
        } else {
            setResult(RESULT_OK, Intent().putExtra("content", text))
            onBackPressed()
        }
    }
}